<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="format-detection" content="telephone=no" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
		<script src="../../script/mui.min.js"></script>
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/swiper-3.4.2.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" href="../../css/base.css"/>
		<link rel="stylesheet" href="../../css/exam.css">
		<title>签到进行中</title>
		<script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
		<style>
			html {
				font-size: 10px;
			}
			#question_div {
				min-height: 400px
			}
			.weui_mask {
				position: fixed;
				z-index: 998;
				top: 0;
				right: 0;
				bottom: 0;
				left: 0;
			}
			.weui_dialog {
				z-index: 999;
			}
			.close_sign_div {
				/*background: #18b4ed;*/
				color: #FFF;
				height: 45px;
			}
			.close_sign_div a {
				line-height: 45px;
				font-size: 14px;
				background: #18b4ed;
				width: 100%;
				color: #FFF;
			}
			.top_sign_info_div {
				margin-top: 20px;
				text-align: center
			}
			.center_sign_img_div {
				/*height: 180px;*/
				text-align: center;
			}
			.center_sign_img_div img {
				height: 280px;
				width: 280px;
			}
			.bottom_sign_num_div {
				text-align: center;
				margin-top: 20px
			}
			.center_vote_div {
				margin-top: 17%
			}
			.yuan {
				text-align: center
			}
			.round-div {
				width: 150px;
				height: 150px;
				border-radius: 50%;
				border: #18b4ed solid 1px;
				margin: 0 auto;
				position: relative;
			}
			.select {
				background-color: #18b4ed;
			}
			.select p {
				color: #fff;
			}
			.unselect p {
				color: #18b4ed;
			}
			.round-div img {
				position: absolute;
				left: 40%;
				top: 30%;
				height: 30px;
				width: 30px;
			}
			.bottom_img_p {
				position: absolute;
				left: 40%;
				bottom: 20%;
				font-size: 16px;
			}
		</style>
	</head>
	<body >
		<div class="stu-test " id="content_div"  style="display: none">
			<div class="ReviewWeekly_div" ></div>
			<div class="space10"></div>
			<div class="k-con test-m-bottom70 test-analysis" id="question_div" >
				<div class="center_vote_div" id="tab">
					<div class="yuan1">
						<div class="round-div unselect">
							<img   class="item_image" src="../../icon/icon_Favor_noselect.png" alt="" />
							<p class="bottom_img_p one_option" ></p>
						</div>
					</div>
					<div class="yuan1 top_40">
						<div class="round-div unselect">
							<img   class="item_image" src="../../icon/icon_Oppose_noselect.png" alt="" />
							<p class="bottom_img_p two_option" >
								反对
							</p>
						</div>
					</div>
				</div>
			</div>
			<div class="k-text-center k-fixed-bottom test-bottom1 close_sign_div" id="sub_div" onclick="closeSignToast()" style="display: none">
				<a>提交</a>
			</div>
		</div>
		<div id="backAlert" class="weui_dialog_confirm" style="display: none">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title" id="checkNum"></strong>
				</div>
				<div class="weui_dialog_bd"></div>
				<div class="weui_dialog_ft">
					<a  href="#" class="weui_btn_dialog default" id="closeTest_no" style="color:#18b4ed">取消</a>
					<a  href="#" class="weui_btn_dialog primary" id="closeTest_yes" style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
		<div class="noSign " hidden="hidden"  id="nullvote">
			<img src="../../icon/icon_vote_null.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无投票活动
			</p>
		</div>
		<div class="noSign " hidden="hidden"  id="endvote">
			<img src="../../icon/icon_vote_end.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				投票活动已结束
			</p>
		</div>
		<div class="noSign" hidden="hidden"  id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<!--<button type="button"  onclick="loadData()"class="mui-btn mui-btn-outlined">
			重新加载
			</button>-->
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/push.js"></script>
	<script type="text/javascript">
		var itemCheck = "3";
		var back_type = "";
		var template = "";
		var userstatus = "1";
		var iid = "";
		var vote_status = "";
		//默认未参加
		apiready = function() {
			SelectSwitch();
			vote_status = api.pageParam.status;
			userstatus = api.pageParam.userstatus;
			template = api.pageParam.template;
			iid = api.pageParam.iid;
			preData(vote_status, userstatus, iid, template)
			
			sendBuriedNotifi('0', '学生端投票页', '189');
			btnClick();
			ReceNotifi();
			setRefreshHeader();
		};
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}
		//下拉刷新
		function setRefreshHeader() {
			api.setRefreshHeaderInfo({
				visible : true,
				bgColor : '#ccc',
				textColor : '#fff',
				textDown : '下拉刷新...',
				textUp : '松开刷新...',
				showTime : true
			}, function(ret, err) {
				getNewVoteMessage('', 1);
			});
		}

		//预加载数据
		function preData(vote_status, userstatus, iid, template) {
			if (!isEmpty(iid)) {
				if (vote_status == 1) {//开始或者进行中
					if (userstatus == 1) {//未参加此次投票
						$('#content_div').show();
						$('#sub_div').show();
						$('#nullvote').hide();
						$('#endvote').hide();
						if (template == 0) {//模板1，赞成反对
							$('.one_option').text('赞成');
							$('.two_option').text('反对');
						} else {
							$('.bottom_img_p').css("left", "44%");
							$('.one_option').text('是');
							$('.two_option').text('否');
						}
					} else {
						$('#nullvote').show();
						$('#endvote').hide();
						$('#content_div').hide();
						$('#sub_div').hide();
					}
				} else if (vote_status == 2) {//结束状态
					$('#endvote').show();
					$('#nullvote').hide();
					$('#content_div').hide();
					$('#sub_div').hide();
				} else {//未发起
					$('#endvote').hide();
					$('#nullvote').show();
					$('#content_div').hide();
					$('#sub_div').hide();
				}
			} else {
				$('#nullvote').show();
				$('#endvote').hide();
				$('#content_div').hide();
				$('#sub_div').hide();
			}
		}

		//接收推送通知
		function ReceNotifi() {
			api.addEventListener({
				name : 'pushMessage_classroomMessage'
			}, function(ret, err) {
				var id = ret.value.id;
				var vote_status = ret.value.status;
				var VOTE_TYPE = ret.value.type;
				if (VOTE_TYPE == 10057) {
					getNewVoteMessage(id, '0');
				}
			});
			api.addEventListener({
				name : 'openSignPopu'
			}, function(ret, err) {
				//coding...
				backToast();
			});
		}

		//获取到最新一条数据
		function getNewVoteMessage(id, type) {
			var jid = $api.getStorage('cfnetppjxid');
			var params = {
				tid : 6,
				jid : jid,
				uid : $api.getStorage('cfnetppuid'),
				rows : 1,
				cid : api.pageParam.cid,
				pid : api.pageParam.pid,
			}
			cfnetppPOST(url_stuGetActivelist, params, false, function(data, status) {
				api.refreshHeaderLoadDone();
				if (status == 'success') {
					if (data.code == 200) {
						if (!isObjectEmpty(data.data)) {
							var Push_id = id;
							iid = data.data[0].iid;
							vote_status = data.data[0].activestatus;
							template = data.data[0].template;
							userstatus = data.data[0].userstatus;
							if (type == 0) {//推送过来
								if (Push_id == data.data[0].iid) {//为同一个活动时
									preData(vote_status, userstatus, iid, template)
								}
							} else {
								preData(vote_status, userstatus, iid, template)
							}
						} else {
							if (type == 0) {//推送过来
								if (Push_id == data.data[0].iid) {//为同一个活动时
									preData(vote_status, userstatus, iid, template)
								}
							} else {
								preData(vote_status, userstatus, iid, template)
							}
						}
					}
				}
			})
		}

		//选项切换
		function SelectSwitch() {
			var myTab = document.getElementById("tab");
			//一个节点
			var myLi = myTab.getElementsByClassName("yuan1");
			//数组
			var myDiv = myTab.getElementsByClassName("round-div");
			var imgDiv = myTab.getElementsByClassName("item_image");
			var fontDiv = myTab.getElementsByClassName("bottom_img_p");
			//数组
			for (var i = 0; i < myLi.length; i++) {
				myLi[i].index = i;
				myLi[i].onclick = function() {
					for (var j = 0; j < myLi.length; j++) {
						myDiv[j].className = "round-div unselect";
						if (j == 0) {//第1个
							imgDiv[j].setAttribute("src", "../../icon/icon_Favor_noselect.png");
						} else {
							imgDiv[j].setAttribute("src", "../../icon/icon_Oppose_noselect.png");
						}
					}
					myDiv[this.index].className = "round-div select";
					if (this.index == 0) {//第1个
						imgDiv[this.index].setAttribute("src", "../../icon/icon_Favor_select.png");
					} else {
						imgDiv[this.index].setAttribute("src", "../../icon/icon_Oppose_select.png");
					}
					itemCheck = this.index;
				}
			}
		}

		//按钮点击事件
		function btnClick() {
			//正常情况下是否退出当前考试按钮取消键
			$('#closeTest_no').click(function() {
				$('#backAlert').hide();
			});
			//正常情况下是否退出当前考试按钮确定键
			$('#closeTest_yes').click(function() {
				$('#backAlert').hide();
				if (back_type == 2) {
					showProgress();
					submitVoteData(itemCheck + 2)
				} else {
					showProgress();
					api.sendEvent({
						name : 'closeSignPopu'
					});
				}
			});
		}

		//退出提示
		function backToast() {
			$('#backAlert').show();
			$('#checkNum').text('是否确定退出当前投票页面?')
			back_type = 1;
		}

		function closeSignToast() {
			if (itemCheck == "3") {
				alert('请提交投票结果');
				return false
			}
			//			$('#backAlert').show();
			//			$('#checkNum').text('是否确定提交?')
			back_type = 2;
			showProgress();
			submitVoteData(itemCheck + 2)
		}

		//提交答题数据
		function submitVoteData(option) {
			var params = {
				iid : iid,
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
				tid : 6,
				status : option,
			}
			cfnetppPOST(url_stuSignYesNo, params, false, function(data, status) {
			SendBusinessOperationsLogNotifi('学生端投票', '189', params, params, '', data, '学生端投票接口', '189-01')
				hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						if (!isObjectEmpty(data)) {
							userstatus = 2;
							ShowToast('提交成功');
							sendNotifi();
							$('#sub_div').hide();
							openVoteScore()
						} else {
							ShowToast('提交失败');
						}
					} else {
						ShowToast(data.message);
					}
					changeSignShare();
				} else {
				}
			})
		}

		//打开学生结果页
		function openVoteScore() {
			SendBehaviorTrajectoriesNotifi_Authentication('1', '学生端投票页', '189', api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname, document.title, '');
			api.openWin({useWKWebView:true,
				name : 'Student_VoteScoreWindow',
				url : 'Student_VoteScoreWindow.html',
				pageParam : {
					iid : iid,
					template : template,
					ismocc : api.pageParam.ismocc,
					sourceurl : window.location.pathname,
					sourcetitle : document.title,
					cid : api.pageParam.cid,
					pid : api.pageParam.pid,
				},
				slidBackEnabled : false,
			});
		}
		//发送通知
		function sendNotifi() {
			api.sendEvent({
				name : 'RefreshVoteClassList'
			});
		}

		//红点的隐藏
		function changeSignShare() {
			var jid = $api.getStorage('cfnetppjxid');
			//投票成功,赋值为没有签到
			$api.setStorage('cfnetppmessageclassroom' + jid + VOTE_START_TYPE + iid, "0");
		}
	</script>
</html>